function loadEditDialog(isEdit) {
    var url1 = "";
    var emplID;
    if (isEdit) {//редактирование
        emplID = document.getElementsByClassName('row_selected')[0].id;
        url1 = "emplData?id=" + emplID;
    }
    else {//добавление
        emplID = 0;
        url1 = "emplData?id=" + emplID;
    }
    $.ajax({
        "url": url1,
        "type": 'GET',
        "success": function (data) {
            document.getElementById('emplData_block').innerHTML = data;
        }
    });
}

function emplDataRedirect(isEdit, nameDialog) {
    $.Dialog({
        "title": nameDialog,
        "draggable": true,
        "content": "<div id='emplData_block'></div>",
        "onShow": loadEditDialog(isEdit),
        "width": 450,
        "height": 450
    });
}
function submitEmployeeData() {
    var form = $('#emplForm').serialize();
    $.ajax({
        "url": 'emplData',
        "type": 'POST',
        "data": form,
        "success": function (data) {
            var err = $(data).find('#cp_validation_error').val();
            if (err=='false'){
            console.log('successful request');
                dialogSuccessfulClose('Изменения приняты.',{background: 'green', color: 'white'});
                redrawDataTable('employee_table');
            }else{
                document.getElementById('emplData_block').innerHTML = data;}
        }
    });
}

function checkAndNewUser() {
    var emplID = document.getElementsByClassName('row_selected')[0].id;
    $.ajax({
        "url":'a_check_if_acc_exists',
        "data":{"emplId":emplID},
        "dataType":'json',
        "success": function(data) {
            if (data.exists) {
                $.Notify({
                    "style": {background: 'red', color: 'white'},
                    "content":"У этого пользователя уже есть аккаунт.",
                    "timeout": 5000
                });
            } else {
                dialogNewUser(emplID);
            }
        }
    });
}